package cn.wjssl.domain.strategy.model.entity;

import cn.wjssl.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * 策略实体类
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyEntity {

    /** 抽奖策略ID */
    private Long strategyId;
    /** 抽奖策略描述 */
    private String strategyDesc;
    /** 抽奖规则模型 rule_weight,rule_blacklist */
    private String ruleModels;

    // 判断 ruleModels 是否为空, 分割rule_model
    public String[] ruleModels2Array() {
        if (StringUtils.isBlank(ruleModels)) return null;
        return ruleModels.split(Constants.SPLIT);
    }

    // 判断 ruleModels 是否含有 rule_weight 权重, 有的话就返回这个rule_model, 不然就返回null
    public String getRuleWeight2ruleModel() {
        String[] ruleModels = ruleModels2Array();
        // 如果 StrategyId 没有配置 rule_weight 会空指针
        if(ruleModels == null || ruleModels.length == 0) return null;
        for (String ruleModel : ruleModels) {
            if ("rule_weight".equals(ruleModel)) return ruleModel;
        }
        return null;
    }

}

